# Maintainer:  Matheus Catarino <matheus-catarino@hotmail.com>

pkgbase=mingw-w64-zig
pkgname="${MINGW_PACKAGE_PREFIX}-zig"
pkgver=0.7.1
pkgrel=2
pkgdesc='Zig is a general-purpose programming language and toolchain for maintaining robust, optimal, and reusable software. (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64')
url='https://ziglang.org'
license=(MIT)
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-lld"
             )
depends=("${MINGW_PACKAGE_PREFIX}-llvm"
         "${MINGW_PACKAGE_PREFIX}-clang"
         )
source=("zig-${pkgver}.tar.gz::https://github.com/ziglang/zig/archive/${pkgver}.tar.gz")
sha512sums=('ad0b36f7b40481aca03940adfd42d34a724922993fc29a23a80412dc087ca6ce4876a400dc9bb7da455564521a88ea205c218988759ff6c56251a08232bfa41a')

build() {
  cd ${srcdir}/zig-${pkgver}
        MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
        ${MINGW_PREFIX}/bin/cmake \
        -G"MSYS Makefiles" \
        -DCMAKE_CXX_COMPILER="clang++" \
        -DCMAKE_C_COMPILER="clang" \
        -DCMAKE_BUILD_TYPE=Release \
        -DZIG_PREFER_CLANG_CPP_DYLIB=true \
        -DZIG_TARGET_TRIPLE="x86_64-windows-gnu" \
        -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
        -B build-${MINGW_CHOST}

  cmake --build build-${MINGW_CHOST} --config release --parallel
}

package() {
  cd ${srcdir}/zig-${pkgver}/build-${MINGW_CHOST}

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --build . --target install
  install -Dm644 "../LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/zig/LICENSE"
}
